package com.digitalchina.lxnsy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.PermissionListVO;

import java.util.List;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.adapter
 * 创建人：郑皓
 * 创建时间：2017/2/21 13:46
 * 修改备注：
 * ================================================
 */
public class ManagementAdapter extends BaseAdapter {

    private List<PermissionListVO> mDatas;
    private Context mContext;
    private final LayoutInflater layoutInflater;
    private int mPosition = -1;

    public ManagementAdapter(Context mContext, List<PermissionListVO> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
        layoutInflater = LayoutInflater.from(this.mContext);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public PermissionListVO getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ManagementAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ManagementAdapter.ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_management, parent, false);
            viewHolder.textView = convertView.findViewById(R.id.name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ManagementAdapter.ViewHolder) convertView.getTag();
        }

        if (mPosition >= 0 && mPosition == position) {
            viewHolder.textView.setTextColor(mContext.getResources().getColor(R.color.app_color));
        } else {
            viewHolder.textView.setTextColor(mContext.getResources().getColor(R.color.colorFontBlack));
        }


        viewHolder.textView.setText(mDatas.get(position).getName());


        return convertView;
    }

    public void setSelectPosition(int position) {
        mPosition = position;
        notifyDataSetChanged();
    }

    public void setDatas(List<PermissionListVO> mDatas) {
        this.mDatas = mDatas;
        notifyDataSetChanged();
    }

    public PermissionListVO getCurrentPositionItem() {
        return mDatas.get(mPosition);
    }

    private static class ViewHolder {
        TextView textView;
    }
}
